package string;

import java.io.*;
import java.util.Random;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 读取words.txt文件 测试速度StringTable长度不同的时间效率
 *      有效长度 1009以上 1.8默认60013
 *      StringTable size of 1000 is invalid; must be between 1009 and 2305843009213693951
 * <P> Date: 2022/3/19:21:54
 * <P> Description:
 */

public class StringTest2 {

    public static void main(String[] args) {
        BufferedReader br = null;
        long l = System.currentTimeMillis();
        try {
            br =  new BufferedReader(new FileReader("words.txt"));
            String data ;
            while ((data = br.readLine())!= null){
                data.intern();//如果data 存在于字符串常量池中 则指向  否则生成
            }



            System.out.println("花费时间" + (System.currentTimeMillis()-l));
            //1009：185  100009：50
            //长度越大 哈希碰撞越少 速度越快
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e){
            e.printStackTrace();
        }

    }

}
